﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers {
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.models.fountain.*;

    public class ShowGiftPopupCommand extends Command {

        private const _isBackendReadyForSurprisePackage:Boolean = true;

		[Inject]
        public var event:InfoEvent;
		[Inject]
        public var sessionModel:SessionModel;
		[Inject]
        public var treeModel:TreeModel;

        override public function execute():void{
            var _local1:Array;
            if (this.event.info == EventConstants.WELCOME_GIFTS_POPUP){
                _local1 = this.getWelcomePopupData();
            } else {
                _local1 = this.getGiftData();
            };
            dispatch(new InfoEvent(EventConstants.CREATE_POPUP, GameConstants.GIFT_POPUP, _local1));
        }
        private function getGiftData():Array{
            var _local2:Array;
            var _local3:String;
            var _local4:String;
            var _local5:String;
            var _local1:Array = new Array();
            _local1.push({amount:50, type:GameConstants.COINS});
            _local1.push({amount:1, type:GameConstants.XP});
            if (this.sessionModel.hasFountain){
                _local2 = [GameConstants.LOVE, GameConstants.FIRE, GameConstants.AIR, GameConstants.WATER, GameConstants.STAR, GameConstants.ICE];
                _local3 = this.treeModel.symbol;
                _local2.splice(_local2.indexOf(_local3), 1);
                _local4 = GameConstants.ICE;
                if (_local3 == GameConstants.ICE){
                    _local4 = this.getRandomKey(_local2);
                };
                _local2.splice(_local2.indexOf(_local4), 1);
                _local5 = this.getRandomKey(_local2);
                _local2.splice(_local2.indexOf(_local5), 1);
                _local1.push({amount:1, type:_local5});
                _local5 = this.getRandomKey(_local2);
                _local2.splice(_local2.indexOf(_local5), 1);
                _local1.push({amount:1, type:_local5});
                _local1.push({amount:1, type:_local3});
                _local1.push({amount:1, type:_local4});
                if (this._isBackendReadyForSurprisePackage){
                    _local1.push({amount:1, type:GameConstants.GIFT_SURPISE_PACKAGE});
                } else {
                    _local1.push({amount:1, type:GameConstants.GIFT_SURPRISE_PLACEHOLDER});
                };
            } else {
                _local1.push({amount:1, type:GameConstants.GIFT_ITEM_PLACEHOLDER});
                _local1.push({amount:1, type:GameConstants.GIFT_ITEM_PLACEHOLDER});
                _local1.push({amount:1, type:GameConstants.GIFT_ITEM_PLACEHOLDER});
                _local1.push({amount:1, type:GameConstants.GIFT_ITEM_PLACEHOLDER});
                _local1.push({amount:1, type:GameConstants.GIFT_SURPRISE_PLACEHOLDER});
            };
            return (_local1);
        }
        private function getWelcomePopupData():Array{
            var _local1:Array = new Array();
            if (((this.sessionModel.hasFountain) && (this._isBackendReadyForSurprisePackage))){
                _local1.push({amount:1, type:GameConstants.GIFT_SURPISE_PACKAGE});
            } else {
                _local1.push({amount:1, type:GameConstants.GIFT_SURPRISE_PLACEHOLDER});
            };
            _local1.push({amount:50, type:GameConstants.COINS});
            _local1.push({amount:3, type:GameConstants.XP});
            return (_local1);
        }
        private function getRandomKey(_arg1:Array):String{
            var _local2:int = Math.floor((Math.random() * _arg1.length));
            var _local3:String = _arg1[_local2];
            return (_local3);
        }

    }
}//package net.wooga.pets.controllers 
